import os
import shutil
from xml.etree import ElementTree as ET

SOURCE_DIR=os.path.join(os.path.split(os.path.realpath(__file__))[0], '../')

def readToolchainrelationList():
    toolchainrelation = ET.parse(os.path.join(SOURCE_DIR, 'toolchainrelationlists.xml')).getroot()
    
    toolchainrelation_list = []
    for product in toolchainrelation:
        for platform in product:
            for component in platform:
                for item in component:
                    toolchainrelation_date = []
                    toolchainrelation_date.append(product.get("name"))
                    toolchainrelation_date.append(platform.get("name"))
                    toolchainrelation_date.append(platform.get("generator"))
                    toolchainrelation_date.append(platform.find("setenv").text)
                    toolchainrelation_date.append(item.get("name"))
                    toolchainrelation_date.append(item.get("cmake_file"))
                    toolchainrelation_list.append(toolchainrelation_date)
    return toolchainrelation_list
    
def readConfig(args_section, args_product, args_platform, args_component):
    toolchainrelation_list=readToolchainrelationList()
    config = ET.parse(os.path.join(SOURCE_DIR, 'config.xml')).getroot()
 
    for remote in config:
        for section in remote:
            name = section.get("name")
            if(args_section == name):
                print(args_section)
                product = section.get("product").split(' ')
                platform = section.get("platform").split(' ')
                if args_product:
                    for pdt in args_product:
                        if pdt in product:
                            print(pdt)
                if args_platform:
                    for plt in args_platform:
                        if plt in platform:
                            print(plt)
                #if(args_product == product):
                #    platform = section.get("platform").split(' ')
